import { smartTranslate as $t, transPlaceholder as $p } from '@/lang';
import { hasAuth } from '@/plugins/permission';


export const getFieldColumns = (options) => {
  return [
    {
      field: 'id',
      title: $t('common.field.id', '编号'),
      width: null,
      align: 'left',
      showOverflow: 'tooltip',
      visible: false,
    },
    {
      field: 'name',
      title: $t('menu.admin.dict.field.name', '名称'),
      width: null,
      align: 'left',
      showOverflow: 'tooltip',
      visible: true,
    },
    {
      field: 'code',
      title: $t('menu.admin.dict.field.code', '代码'),
      width: null,
      align: 'left',
      showOverflow: 'tooltip',
      visible: true,
    },
    {
      field: 'level',
      title: $t('menu.admin.dict.field.level', '级别'),
      width: 'auto',
      align: 'left',
      visible: true,
      cellRender: {
        name: 'RaElSelectRender',
        options: options.value['level'],
        props: {
          multiple: false,
        },
      },
      editRender: {
        enabled: hasAuth('admin:dict:modify'),
        name: 'RaElSelectRender',
        props: {
          options: options.value['level'],
          placeholder: $p('menu.admin.dict.field.level', '级别', 'select'),
          multiple: false,
        },
      },
    },
    {
      field: 'type',
      title: $t('menu.admin.dict.field.type', '类型'),
      width: 'auto',
      align: 'left',
      visible: true,
      cellRender: {
        name: 'RaElSelectRender',
        options: options.value['type'],
        props: {
          multiple: false,
        },
      },
      editRender: {
        enabled: hasAuth('admin:dict:modify'),
        name: 'RaElSelectRender',
        props: {
          options: options.value['type'],
          placeholder: $p('menu.admin.dict.field.type', '类型', 'select'),
          multiple: false,
        },
      },
    },
    {
      field: 'sql',
      title: $t('menu.admin.dict.field.sql', '设置'),
      width: null,
      align: 'left',
      showOverflow: 'tooltip',
      visible: false,
    },
    {
      field: 'remark',
      title: $t('common.field.remark', '备注'),
      width: null,
      align: 'left',
      showOverflow: 'tooltip',
      visible: true,
      editRender: {
        enabled: hasAuth('admin:dict:modify'),
        name: 'ElInput',
        props: {
          placeholder: $p('common.field.remark', '备注'),
        },
      },
    },
    {
      field: 'sort',
      title: $t('common.field.sort', '排序'),
      width: 70,
      align: 'left',
      showOverflow: 'tooltip',
      visible: true,
      sortable: true,
      dragSort: hasAuth('admin:dict:drag'),
    },
    {
      field: 'status',
      title: $t('common.field.status', '状态'),
      width: 90,
      align: 'left',
      visible: true,
      cellRender: {
        name: 'RaDictSelectRender',
        props: {
          type: 'switch',
          code: 'status_options',
          multiple: false,
        },
      },
    },
    {
      field: 'create_id',
      title: $t('common.field.create_id', '创建用户ID'),
      width: null,
      align: 'left',
      showOverflow: 'tooltip',
      visible: false,
    },
    {
      field: 'create_time',
      title: $t('common.field.create_time', '创建时间'),
      width: 160,
      align: 'left',
      visible: false,
      cellRender: {
        name: 'ElDatePicker',
        props: {
          type: 'date',
          format: 'YYYY-MM-DD HH:mm:ss',
        },
      },
    },
    {
      field: 'update_time',
      title: $t('common.field.update_time', '更新时间'),
      width: 160,
      align: 'left',
      visible: false,
      cellRender: {
        name: 'ElDatePicker',
        props: {
          type: 'date',
          format: 'YYYY-MM-DD HH:mm:ss',
        },
      },
    },


    // 结束
  ];
};

export const getActionButtons = ({ actions }) => [
  {
    content: $t('common.action.update', '修改'),
    type: 'warning',
    icon: 'Edit',
    link: true,
    visible: hasAuth('admin:dict:update'),
    code: 'update_handle',
    onClick: (row) => actions.dispatchAction('update_handle', row),
  },
  {
    content: $t('common.action.detail', '详情'),
    type: 'info',
    icon: 'View',
    link: true,
    visible: hasAuth('admin:dict:detail'),
    code: 'detail_handle',
    onClick: (row) => actions.dispatchAction('detail_handle', row),
  },


  // 结束
];

export const getFormData = (options) => ({
  name: null,
  code: null,
  level: null,
  type: null,
});

export const getFormItems = (options) => [
  {
    field: 'name',
    title: $t('menu.admin.dict.field.name', '名称'),
    folding: true,
    resetValue: null,
    itemRender: {
      name: 'ElInput',
      props: {
        placeholder: $t('common.message.placeholder.general', '请输入{field}',{field: $t('menu.admin.dict.field.name', '名称')}),
        clearable: true,
      },
    },
  },
  {
    field: 'code',
    title: $t('menu.admin.dict.field.code', '代码'),
    folding: true,
    resetValue: null,
    itemRender: {
      name: 'ElInput',
      props: {
        placeholder: $t('common.message.placeholder.general', '请输入{field}',{field: $t('menu.admin.dict.field.code', '代码')}),
        clearable: true,
      },
    },
  },
  {
    field: 'level',
    title: $t('menu.admin.dict.field.level', '级别'),
    folding: true,
    resetValue: null,
    itemRender: {
      name: 'ElSelect',
      options: options.value['level'],
      props: {
          placeholder: $t('common.message.placeholder.general', '请输入{field}',{field: $t('menu.admin.dict.field.level', '级别')}),
          clearable: true,
      },
    },
  },
  {
    field: 'type',
    title: $t('menu.admin.dict.field.type', '类型'),
    folding: true,
    resetValue: null,
    itemRender: {
      name: 'ElSelect',
      options: options.value['type'],
      props: {
          placeholder: $t('common.message.placeholder.general', '请输入{field}',{field: $t('menu.admin.dict.field.type', '类型')}),
          clearable: true,
      },
    },
  },


  // 结束
];
